#include "regist.h"
#include "ui_regist.h"

Regist::Regist(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Regist)
{
    ui->setupUi(this);
    design_page();
    database_regist.setConnectByName("E:\\QtWord\\build-register_page-Desktop_Qt_5_14_2_MinGW_64_bit-Debug\\asdf.db" , "regist");

}

Regist::~Regist()
{
    delete ui;
}

void Regist::design_page()
{
    this->setFixedSize(800 , 480);

    ui->account->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                 "color: rgb(31,31,31);"		//字体颜色
                                 "padding-left:20px;"       //内边距-字体缩进
                                 "background-color: rgb(255, 255, 255);" //背景颜色
                                 "border:2px solid rgb(20,196,188);border-radius:15px;");//边框粗细-颜色-圆角设置

    ui->passward->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                "color: rgb(31,31,31);"		//字体颜色
                                "padding-left:20px;"       //内边距-字体缩进
                                "background-color: rgb(255, 255, 255);" //背景颜色
                                "border:2px solid rgb(20,196,188);border-radius:15px;");//边框粗细-颜色-圆角设置

    ui->repassward->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                "color: rgb(31,31,31);"		//字体颜色
                                "padding-left:20px;"       //内边距-字体缩进
                                "background-color: rgb(255, 255, 255);" //背景颜色
                                "border:2px solid rgb(20,196,188);border-radius:15px;");//边框粗细-颜色-圆角设置



    ui->make_sure->setStyleSheet("QPushButton{font: 25 14pt '微软雅黑 Light';"
                             "color: rgb(255,255,255);"
                             "background-color: rgb(20,196,188);"
                             "border: none;border-radius:15px;}"
                             "QPushButton:hover{background-color: rgb(22,218,208);}"//hover
                             "QPushButton:pressed{background-color: rgb(17,171,164);}");

    ui->exit->setStyleSheet("QPushButton{font: 25 14pt '微软雅黑 Light';"
                              "color: rgb(255,255,255);"
                              "background-color: rgb(20,196,188);"
                              "border: none;border-radius:15px;}"
                              "QPushButton:hover{background-color: rgb(22,218,208);}"//hover
                              "QPushButton:pressed{background-color: rgb(17,171,164);}");
}

void Regist::on_exit_clicked()
{
    this->nativeParentWidget()->show();
    this->hide();

}

void Regist::on_make_sure_clicked()
{
    QSqlDatabase db = database_regist.getConnectByName("regist");
    QString ret;
    ret = database_regist.findUser_Pssward(db , ui->account->text());
    if(NULL == ret){
        if(ui->passward->text() == ui->repassward->text()){
            database_regist.insertUser(db , ui->account->text() , ui->passward->text());
        }else{
            QMessageBox::warning(this, tr("提示"),
                                 tr("两次输入的密码不相同！"),
                                 QMessageBox::Ok);
        }

    }else{
        QMessageBox::warning(this, tr("提示"),
                             tr("账号已存在！"),
                             QMessageBox::Ok);
    }
}
